<?php session_start(); require_once('../connections/con_gl.php'); ?>
<?php
session_start();
//cekAkses($_SESSION[akses],"DD-2-4");
mysql_select_db($database_con_gl, $con_gl);
$query_klas = "SELECT kategori_id, kategori_nama FROM dcm_tm_kategori_dokumen ORDER BY kategori_nama ASC";
$klas = mysql_query($query_klas, $con_gl) or die(mysql_error());
$row_klas = mysql_fetch_assoc($klas);
$totalRows_klas = mysql_num_rows($klas);
//print_r($row_klas);

$query_status = "SELECT status_id, status_nama FROM dcm_ref_status_dokumen ORDER BY status_nama ASC";
$status = mysql_query($query_status, $con_gl) or die(mysql_error());
$row_status = mysql_fetch_assoc($status);
$totalRows_status = mysql_num_rows($status);

$query_action = "SELECT action_id, action_name FROM dcm_action ORDER BY action_name ASC";
$action = mysql_query($query_action, $con_gl) or die(mysql_error());
$row_action = mysql_fetch_assoc($action);
$totalRows_action = mysql_num_rows($action);

$query_unitbisnis = "SELECT unitbisnis_id, unitbisnis_nama FROM dcm_tm_unitbisnis ORDER BY unitbisnis_nama ASC";
$unitbisnis = mysql_query($query_unitbisnis, $con_gl) or die(mysql_error());
$row_unitbisnis = mysql_fetch_assoc($unitbisnis);
$totalRows_unitbisnis = mysql_num_rows($unitbisnis);

mysql_select_db($database_con_gl, $con_gl);
$query_getdata = "select * from v_document where dokumen_id='$_GET[id]'";
//$query_getdata .=" ORDER BY tipe, arsip";
$getdata = mysql_query($query_getdata, $con_gl) or die(mysql_error());
$row_getdata = mysql_fetch_assoc($getdata);
//print_r($row_getdata);
?>
<link type="text/css" rel="stylesheet" href="../css/style.css" />
<link type="text/css" rel="stylesheet" href="../css/jquery.wysiwyg.css" />
<script type="text/javascript" src="../js/jquery.js"></script>
<script type="text/javascript" src="../js/jquery.wysiwyg.js"></script>
<!--
<script type="text/javascript">
$(function()
  {
	  $('#department').hide();
	  $('#keterangan').wysiwyg();
	   $( '#katagori' ).change(function() {
		    
			 
			 var selected = $('#katagori option:selected').text();
			 var kode = '';	
	
			 switch(selected){
					  case 'FORM':
					   kode = 'FRM';
					    $('#department').show();
					    break;
					  case 'Instruksi Kerja':
					   kode = 'IK';
					   $('#department').show();
					    break;
					  case 'Pedoman Mutu':
					   kode = 'PDN';
					    $('#department').hide();
					    break;
					  case 'Prosedur Mutu':
					  $('#department').show();
					   kode = 'PSN';
				}
			 
			$('#no_document').val('CCG/'+kode+'/');
		    
		});
  });
 
</script>
-->
<body style="background:none;padding:8px;">
<?php if(isset($_POST['Save']))
 { ?>
<?php
// validasi data
$no_doc = $_POST['no_document'];
$nama_doc = $_POST['nama_document'];
$kat = $_POST['katagori'];
$status = $_POST['status'];; // untuk add pertama adalah request approval //$_POST['status'];
$action = $_POST['action'];; // in progress approval //$_POST['action'];
//$ars = $_POST['arsip'];
$unitbisnis= $_POST['unitbisnis'];
$fars= $_POST['filearsip'];
$ket = $_POST['keterangan'];
$keteranganadmin = $_POST['keteranganadmin'];
$f_tmp = $_FILES['filearsip']['tmp_name'];
$f_nam = str_replace(" ","",strtolower($_FILES['filearsip']['name']));
$f_tip = $_FILES['filearsip']['type'];

//echo $f_tip;
if (isset($error)) {
?>
<div id="loading" style="color:#FFF;border:solid 1px #F00;padding:5px;background:#F00;"><?php echo "<img src=\"../images/alert.png\" width=\"16\" align=\"left\"/>&nbsp;&nbsp;<b style=\"color:#FFF;\">Error : </b> <br />".implode("<br />", $error); ?></div>
<?php }else{ ?>
<div id="loading" style="color:#1a4d80;border:solid 1px #215800;padding:5px;background:#F0FFED;">
<?php
$today = date("Y-m-d");
	$query = "update dcm_tm_dokumen set unitbisnis_id='$unitbisnis',kategori_id='$kat',dokumen_no='$no_doc',dokumen_nama='$nama_doc', keterangan_admin='$keteranganadmin',updated_by='$_SESSION[nama]'";
	$f_dest = "../data_arsip/".$f_nam;
	if($f_tmp <>'') {
		copy($f_tmp,$f_dest);
		
		if(file_exists("../data_arsip/".$_POST['filearsip'])) { 
			unlink("../data_arsip/".$_POST['filearsip']);
			$query .=" ,tipe='$f_tip',path_url='$f_nam'";
		}
	}
	//$query  .=
	$query .=" where dokumen_id= '$row_getdata[dokumen_id]';";
	print_r($query);
	mysql_select_db($database_con_gl, $con_gl);
	if(mysql_query($query, $con_gl)) {
		echo "<img src=\"../images/ok.png\" align=\"left\" width=\"16\">&nbsp;&nbsp;Tambah Arsip berhasil ...";
		echo "<script>top.opener.location.reload();self.close();</script>";
	}else{
		echo "<img src=\"../images/alert.png\" width=\"16\" align=\"left\"/>&nbsp;&nbsp;<b style=\"color:#FFF;\">Error : </b> <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- Tambah Arsip gagal, coba lagi !!!";	
	}
	
		
	
?>
</div>
<?php

 } ?>
<?php } ?>
<h1>Edit Data Document</h1>
<form action="" method="POST" enctype="multipart/form-data" name="add" id="add" >
  <table width="100%" border="0" align="center" cellpadding="5" cellspacing="0" class="datatable">
    <tr valign="top">
      <td align="right" bgcolor="#FFFFFF">Katagori  : </td>
      <td bgcolor="#FFFFFF"><select name="katagori" id="katagori" style="width:200px;">
         <?php if($totalRows_klas > 0) { do { ?> 	
		<option value="<?php echo $row_klas['kategori_id'];?>" <?php if($row_klas['kategori_id']==$row_getdata['kategori_id']) { ?>selected="selected"<?php } ?>><?php echo $row_klas['kategori_nama'];?></option>
          <?php }while($row_klas = mysql_fetch_assoc($klas)); } ?>
      </select></td>
    </tr>
    <tr id='department' valign="top">
      <td align="right" bgcolor="#FFFFFF">Department : </td>
      <td bgcolor="#FFFFFF"><select name="unitbisnis" id="unitbisnis" style="width:200px;">
              
	  
	    <?php if($totalRows_unitbisnis > 0) { do { ?> 	
		<option value="<?php echo $row_unitbisnis['unitbisnis_id'];?>" <?php if($row_unitbisnis['unitbisnis_id']==$row_getdata['unitbisnis_id']) { ?>selected="selected"<?php } ?>><?php echo $row_unitbisnis['unitbisnis_nama'];?></option>
          <?php }while($row_unitbisnis = mysql_fetch_assoc($unitbisnis)); } ?>
      </select></td>
    </tr>
    <tr valign="top">
      <td align="right" bgcolor="#FFFFFF">No Document</td>
      <td bgcolor="#FFFFFF"><input name="no_document" type="text" id="no_document" size="37" maxlength="100" value="<?php echo $row_getdata['NODOCUMENT'];?>" /></td>
    </tr>
    <tr valign="top">
      <td align="right" bgcolor="#FFFFFF">Nama Document</td>
      <td bgcolor="#FFFFFF"><input name="nama_document" type="text" id="nama_document" value="<?php echo $row_getdata['NAMADOCUMENT'];?>"size="37" maxlength="100" /></td>
    </tr>

    <tr valign="top">
      <td align="right" bgcolor="#FFFFFF">Status Document :</td>
      <td bgcolor="#FFFFFF"><?php echo $row_getdata['STATUS'];?></td>
    </tr>
  
    <tr valign="top">
      <td align="right" bgcolor="#FFFFFF">Upload Document :</td>
      <td bgcolor="#FFFFFF"><input type="file" name="filearsip" id="filearsip"/></td>
    </tr>
    <tr valign="top">
      <td align="right" bgcolor="#FFFFFF">Keterangan Verifikator:</td>
      <td bgcolor="#FFFFFF"><textarea name="keterangan" cols="85" rows="5" id="keterangan" readonly="readonly"><?php echo $row_getdata['keterangan'];?></textarea></td>
    </tr>
    <tr valign="top">
      <td width="20%" align="right" bgcolor="#FFFFFF">Keterangan Admin:</td>
      <td width="80%" bgcolor="#FFFFFF"><label>
      <textarea name="keteranganadmin" cols="85" rows="5" id="keteranganadmin"><?php echo $row_getdata['keterangan_admin'];?></textarea>
      <input name="id" type="hidden" id="id" />
      <input name="kontak" type="hidden" id="kontak" value="<?php echo $_GET['id'];?>" />
      </label></td>
    </tr>
    <tr valign="top">
      <td align="right" bgcolor="#FFFFFF">&nbsp;</td>
      <td bgcolor="#FFFFFF"><label></label></td>
    </tr>
    <tr>
      <td align="left" bgcolor="#FFFFFF"><em>*Harus diisi
        <input name="open" type="hidden" id="open" value="<?php echo $_GET['open'];?>" />

      </em></td>
      <td bgcolor="#FFFFFF"><label>
        <input name="Save" type="submit" id="Save" value="Simpan" />
        </label>
        <label>
          <input type="button" name="Button" value="Batal" onClick="javascript:window.close(2000);" />
          <!--<input type="button" name="Button" value="Batal" onClick="javascript:window.close(2000);" />-->
        </label></td>
    </tr>
  </table>
</form>
</body>